package com.easy.framework.security.model;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;

import java.util.*;

@Getter
@Setter
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class LoginUser extends User implements OAuth2AuthenticatedPrincipal {

    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;

    private Long userId;

    private String name;

    private List<Dept> depts;

    private List<Role> roles;

    private String ip;

    private String location;

    private String browser;

    private String os;

    private Long loginAt;

    public LoginUser(){
        super(null,null,null);
    }

    public LoginUser(Long userId, String username, String password, String name,
                     List<Dept> depts, List<Role> roles,
                     Collection<? extends GrantedAuthority> authorities) {
        super(username, password, authorities);
        this.userId = userId;
        this.depts = depts;
        this.roles = roles;
        this.name = name;
        this.loginAt = System.currentTimeMillis();
    }

    public LoginUser(Long userId, String username, String password, String name,
                     List<Dept> depts, List<Role> roles,
                     boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked,
                     Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.userId = userId;
        this.depts = depts;
        this.roles = roles;
        this.name = name;
        this.loginAt = System.currentTimeMillis();
    }

    @Override
    public Map<String, Object> getAttributes() {
        return Collections.emptyMap();
    }
}
